package com.base.controller;

import com.base.entity.DictEntity;
import com.base.service.DictService;
import com.base.utils.PageUtils;
import com.base.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2020-12-11 14:33:17
 */
@RestController
@RequestMapping("sys/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:dict:list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = dictService.getDictList(params);

        return Result.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:dict:info")
    public Result info(@PathVariable("id") String id) {
        DictEntity dict = dictService.getById(id);

        return Result.success(dict);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:dict:save")
    public Result save(@RequestBody DictEntity dict) {
        dictService.saveDict(dict);

        return Result.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:dict:update")
    public Result update(@RequestBody DictEntity dict) {
        dictService.saveOrUpdateDict(dict);

        return Result.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:dict:delete")
    public Result delete(@RequestBody String[] ids) {
        dictService.removeByIds(Arrays.asList(ids));

        return Result.success();
    }

}
